package com.atguigu.yygh.order.controller;


import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.common.utils.JwtHelper;
import com.atguigu.yygh.model.order.OrderInfo;
import com.atguigu.yygh.order.service.OrderInfoService;
import com.atguigu.yygh.vo.order.OrderCountQueryVo;
import com.atguigu.yygh.vo.order.OrderQueryVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2022-11-16
 */
@RestController
@RequestMapping("/order/orderInfo")
public class OrderInfoController {

    @Autowired
    private OrderInfoService orderInfoService;

    @PostMapping("/submitOrder/{scheduleId}/{patientId}")
    public R submitOrder(@PathVariable String scheduleId, @PathVariable Long patientId){
        Long orderId = orderInfoService.submitOrder(scheduleId,patientId);
        return R.ok().data("orderId",orderId);
    }

    @GetMapping("/{pageNum}/{pageSize}")
    public R getPageList(@PathVariable Integer pageNum, @PathVariable Integer pageSize, @RequestHeader String token, OrderQueryVo orderQueryVo){
        Page<OrderInfo> pageModel = orderInfoService.getPageList(pageNum,pageSize, JwtHelper.getUserId(token),orderQueryVo);
        return R.ok().data("pageModel",pageModel);
    }

    @GetMapping("/getStatusList")
    public R getStatusList(){
        List<Map<String,Object>> statusList = orderInfoService.statusList();
        return R.ok().data("statusList",statusList);
    }

    @GetMapping("/getOrders/{orderId}")
    public R getOrders(@PathVariable Long orderId){
        OrderInfo orderInfo = orderInfoService.getOrders(orderId);
        return R.ok().data("orderInfo",orderInfo);
    }

    @GetMapping("/cancelOrder/{orderId}")
    public R cancelOrder(@PathVariable Long orderId){
        orderInfoService.cancelOrder(orderId);
        return R.ok();
    }

    @PostMapping("/getCountMap")
    public Map<String,Object> getCountMap(@RequestBody OrderCountQueryVo orderCountQueryVo){
        return orderInfoService.getCountMap(orderCountQueryVo);
    }
}

